/**
 * Created by De Niro on 2015/4/24.
 */
app.filter('hyContactEverTalk',function(){
    return function(hyContact){
        var hyContactOnline = [],
            temp;
        for(temp in hyContact){
            if(hyContact.hasOwnProperty(temp)){
                if(hyContact[temp]['everTalk']){
                    hyContact[temp]['id'] = temp;
                    hyContactOnline.push(hyContact[temp]);
                }
            }
        }
        return hyContactOnline;
    }
}).filter('hyMessageOfSomeOne',function(){
    return function(hyMessage,id,hyContact,hyUser){
        var tempNum = 0 ;
        var result = [];
        if(hyContact == undefined || hyContact == ""){
            return;
        }
        if(hyContact[id]['group']){
            for(;tempNum < hyMessage.length;tempNum++){
                if(hyMessage[tempNum]['receiver'] == id){
                    result.push(hyMessage[tempNum]);
                }
            }
        }else{
            for(;tempNum < hyMessage.length;tempNum++){
                if((hyMessage[tempNum]['sender'] == id && hyMessage[tempNum]['receiver'] == hyUser.id)||(hyMessage[tempNum]['receiver'] == id && hyMessage[tempNum]['sender'] == hyUser.id)){
                    result.push(hyMessage[tempNum]);
                }
            }
        }
        return result;
    }
}).filter('hyContactToInvite',function(){
    //id为当前正在聊天的人的id
    return function(hyContact,id){
        var hyContactToInvite = [],
            temp;
        if(hyContact == undefined || hyContact == ""){
            return;
        }
        if(!hyContact[id]['group']){
            for(temp in hyContact){
                if(hyContact.hasOwnProperty(temp)){

                    if(hyContact[temp]['id'] != id && !hyContact[temp]['group'] && hyContact[temp]['online']){
                        hyContact[temp]['id'] = temp;
                        hyContactToInvite.push(hyContact[temp]);
                    }
                }
            }
            return hyContactToInvite;
        }else{
            for(temp in hyContact){
                if(hyContact.hasOwnProperty(temp)){
                    if(($.inArray(temp, hyContact[id]['member'])<0)&& !hyContact[temp]['group'] && hyContact[temp]['online']){
                        hyContact[temp]['id'] = temp;
                        hyContactToInvite.push(hyContact[temp]);
                    }
                }
            }
            return hyContactToInvite;
        }
    }
});